limsQualitycontrolTestBatch.editPage = {
    /*
        getGridParam: function () {
            var _this = this;
            return {
                type: 'grid',
                id: 'lims-qualitycontrol-test-batch-edit-list-grid',
                url: limsQualitycontrolTestBatch.baseUrl + '/queries/raw',
                service: 'limsQualitycontrolTestBatchServiceImpl',
                dbTable: 'T_LIMS_QUALITYCONTROL_TEST_BATCH',
                columns: limsQualitycontrolTestBatch.getEditListColumns(),
                onCellClick: function (field, row) {
                    field === 'id' && _this.loadDetailPage(row.id);
                },
                requestData: {
                    status_EQ: '0'
                },
                onLoadSuccess: function (data) {
                    if (!Gikam.isEmpty(data)) {
                        this.activeRowByIndex(0);
                    } else {
                        Gikam.cleanCompData(['lims-qualitycontrol-test-result-edit-list-grid']);
                    }
                },
                deleteFormatter: function (row) {
                    return row.qualityControlTestBatchCode
                },
                page: true,
                onRowActive: function (index, row) {
                    Gikam.getAsyncComp('lims-qualitycontrol-test-result-edit-list-grid').done(function (grid) {
                        grid.refresh({
                            url: limsQualitycontrolTestBatch.resultBaseUrl + '/queries',
                            requestData: {
                                controlTestBatchId_EQ: row.id
                            }
                        });
                    });
                },
                activateFirstRow: true,
                toolbar: [{
                    type: 'button',
                    text: 'GIKAM.BUTTON.INSERT',
                    icon: 'add',
                    onClick: function () {
                        // Gikam.preInsert({
                        //     modalTitle: 'BASELINE.BASEDATA.QUALITYCONTROLRESULTS.MODAL.ADD',
                        //     fields: limsQualitycontrolTestBatch.getBaseInfoFormFields(),
                        //     url: limsQualitycontrolTestBatch.baseUrl
                        // }).done(function (id) {
                        //     Gikam.getComp('lims-qualitycontrol-test-batch-edit-list-grid').refresh();
                        // });

                        Gikam.postText(limsQualitycontrolTestBatch.baseUrl, Gikam.getJsonWrapper(null, [null, [{}]])).done(function (id) {
                            Gikam.getComp('lims-qualitycontrol-test-batch-edit-list-grid').refresh();
                        });
                    }
                }, {
                    type: 'button',
                    text: 'GIKAM.BUTTON.DELETE',
                    icon: 'remove-row',
                    onClick: function () {
                        Gikam.getComp('lims-qualitycontrol-test-batch-edit-list-grid').deleteRows(limsQualitycontrolTestBatch.baseUrl);
                    }
                }, {
                    type: 'button',
                    text: 'GIKAM.WORKFLOW.BUTTON.SUBMIT',
                    icon: 'submit',
                    onClick: function () {
                        var selections = Gikam.getComp('lims-qualitycontrol-test-batch-edit-list-grid').getSelections()
                        if (Gikam.isEmpty(selections)) {
                            Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
                            return
                        }
                        Gikam.confirm('GIKAM.MODAL.SUBMIT', 'GIKAM.TIP.SUBMIT', function () {
                            var commitUrl = limsQualitycontrolTestBatch.baseUrl + '/committo'
                            Gikam.postText(commitUrl, Gikam.getJsonWrapper(null, [null, selections])).done(function (req) {
                                Gikam.getComp('lims-qualitycontrol-test-batch-edit-list-grid').refresh()
                            })
                        })
                    }
                }]
            }
        },

        getSubmittedGridParam: function () {
            var _this = this;
            return {
                type: 'grid',
                id: 'lims-qualitycontrol-test-batch-edit-list-grid-submitted',
                // url: limsQualitycontrolTestBatch.baseUrl + '/queries/raw',
                service: 'limsQualitycontrolTestBatchServiceImpl',
                dbTable: 'T_LIMS_QUALITYCONTROL_TEST_BATCH',
                columns: limsQualitycontrolTestBatch.getEditListColumns(),
                onCellClick: function (field, row) {
                    field === 'id' && _this.loadDetailPage(row.id);
                },
                requestData: {
                    status_EQ: '1'
                },
                onLoadSuccess: function (data) {
                    if (!Gikam.isEmpty(data)) {
                        this.activeRowByIndex(0);
                    } else {
                        Gikam.cleanCompData(['lims-qualitycontrol-test-result-edit-list-grid']);
                    }
                },
                page: true,
                onRowActive: function (index, row) {
                    Gikam.getAsyncComp('lims-qualitycontrol-test-result-edit-list-grid').done(function (grid) {
                        grid.refresh({
                            url: limsQualitycontrolTestBatch.resultBaseUrl + '/queries',
                            requestData: {
                                controlTestBatchId_EQ: row.id
                            }
                        });
                    });
                },
                activateFirstRow: true
            }
        },*/

    /*    loadDetailPage: function (id) {
            workspace.window.load(limsQualitycontrolTestBatch.baseUrl + '/page/detail' + Gikam.param({
                id: id
            }));
        },*/

    getResultGridParam: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'lims-qualitycontrol-test-result-edit-list-grid',
            url: limsQualitycontrolTestBatch.resultBaseUrl + '/queries',
            requestData: {
                status_EQ: '0'
            },
            service: 'limsQualitycontrolTestResultServiceImpl',
            dbTable: 'T_LIMS_QUALITYCONTROL_TEST_RESULT',
            columns: limsQualitycontrolTestBatch.getResultEditListColumns(),
            onCellClick: function (field, row) {
                field === 'controlMaterialName' && _this.loadEditRecordPage(row);
            },
            deleteFormatter: function (row) {
                return row.controlMaterialName
            },
            page: true,
            toolbar: [{
                type: 'button',
                text: 'GIKAM.BUTTON.INSERT',
                icon: 'add',
                onClick: function () {
                    _this.insertQualityControlResult()
                }
            }, {
                type: 'button',
                text: 'GIKAM.BUTTON.DELETE',
                icon: 'remove-row',
                onClick: function () {
                    Gikam.getComp('lims-qualitycontrol-test-result-edit-list-grid').deleteRows(limsQualitycontrolTestBatch.resultBaseUrl);
                }
            }, {
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.SUBMIT',
                icon: 'submit',
                onClick: function () {
                    var grid = Gikam.getComp('lims-qualitycontrol-test-result-edit-list-grid')
                    var selections = grid.getSelections()
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
                        return
                    }
                    Gikam.confirm('GIKAM.MODAL.SUBMIT', 'GIKAM.TIP.SUBMIT', function () {
                        var commitUrl = limsQualitycontrolTestBatch.resultBaseUrl + '/submit'
                        Gikam.postText(commitUrl, Gikam.getJsonWrapper(null, [null, selections])).done(function (req) {
                            grid.refresh()
                        })
                    })
                }
            }]
        }
    },

    getSubmittedResultGridParam: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'lims-qualitycontrol-test-result-submitted-list-grid',
            // url: limsQualitycontrolTestBatch.resultBaseUrl + '/queries',
            requestData: {
                status_EQ: '1'
            },
            service: 'limsQualitycontrolTestResultServiceImpl',
            dbTable: 'T_LIMS_QUALITYCONTROL_TEST_RESULT',
            columns: limsQualitycontrolTestBatch.getResultEditListColumns(),
            onCellClick: function (field, row) {
                field === 'controlMaterialName' && _this.loadEditRecordPage(row);
            },
            deleteFormatter: function (row) {
                return row.controlMaterialName
            },
            readonly: true,
            page: true,
            toolbar: [{
                type: 'button',
                text: 'AUDIT.PROCESS_UNDO',
                icon: 'submit',
                onClick: function () {
                    var grid = Gikam.getComp('lims-qualitycontrol-test-result-submitted-list-grid')
                    var selections = grid.getSelections()
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
                        return
                    }
                    Gikam.confirm('GIKAM.MODAL.SUBMIT', 'GIKAM.TIP.SUBMIT', function () {
                        var commitUrl = limsQualitycontrolTestBatch.resultBaseUrl + '/back'
                        Gikam.postText(commitUrl, Gikam.getJsonWrapper(null, [null, selections])).done(function (req) {
                            grid.refresh()
                        })
                    })
                }
            }]
        }
    },

    getMainResultTabs: function () {
        var _this = this
        var first = false
        return {
            type: 'tab',
            panels: [{
                title: 'BASEMODULE.RM.ENVIRONMENTS.TAB.UN_SUBMIT_TAB',
                items: [_this.getResultGridParam()]
            }, {
                title: 'BASEMODULE.RM.ENVIRONMENTS.TAB.SUBMITTED_TAB',
                items: [_this.getSubmittedResultGridParam()]
            }],
            onActived: function (data) {
                var tab = Gikam.getComp('main-tab');
                switch (data.index) {
                    case 0:
                        if (first) {  // 首次加载页面时，不操作
                            Gikam.getAsyncComp('lims-qualitycontrol-test-result-edit-list-grid').done(function (grid) {
                                grid.refresh()
                            })
                        }
                        break
                    case 1:
                        Gikam.getAsyncComp('lims-qualitycontrol-test-result-submitted-list-grid').done(function (grid) {
                            grid.refresh({
                                url: limsQualitycontrolTestBatch.resultBaseUrl + '/queries',
                            })
                        })
                        break
                }
                first = true;
            }
        }
    },

    insertQualityControlResult: function () {
        var _this = this;
        Gikam.create('modal', {
            title: Gikam.choose.getConfig("qualitycontrolplan-choose-list").title,
            url: IFM_CONTEXT + Gikam.choose.getConfig("qualitycontrolplan-choose-list").url,
            onAfterClose: function (data) {
                if (!Gikam.isEmpty(data)) {
                    var saveUrl = limsQualitycontrolTestBatch.resultBaseUrl + '/insert-testresult'
                    Gikam.postText(saveUrl, Gikam.getJsonWrapper(null, [null, [data.planRow]], [null, data.projectRows], [null, [{}]])).done(function (req) {
                        Gikam.getAsyncComp('lims-qualitycontrol-test-result-edit-list-grid').done(function (grid) {
                            grid.refresh()
                        });
                    })
                }
            }
        });
    },

    /*    getMainTab: function () {
            var _this = this
            var first = false
            return {
                type: 'tab',
                panels: [{
                    title: 'BATCHEDITLIST.TAB.TITLE.NOTSUBMIT',
                    items: [_this.getGridParam()]
                }, {
                    title: 'BATCHEDITLIST.TAB.TITLE.SUBMITTED',
                    items: [_this.getSubmittedGridParam()]
                }],
                onActived: function (data) {
                    var tab = Gikam.getComp('main-tab');
                    switch (data.index) {
                        case 0:
                            if (first) {  // 首次加载页面时，不操作
                                Gikam.getAsyncComp('lims-qualitycontrol-test-batch-edit-list-grid').done(function (grid) {
                                    grid.refresh()
                                })
                                Gikam.getAsyncComp('lims-qualitycontrol-test-result-edit-list-grid').done(function (grid) {
                                    grid.showToolbar()
                                })
                            }
                            break
                        case 1:
                            Gikam.getAsyncComp('lims-qualitycontrol-test-batch-edit-list-grid-submitted').done(function (grid) {
                                grid.refresh({
                                    url: limsQualitycontrolTestBatch.baseUrl + '/queries/raw',
                                })
                            })
                            Gikam.getAsyncComp('lims-qualitycontrol-test-result-edit-list-grid').done(function (grid) {
                                grid.hideToolbar()
                            })
                            break
                    }
                    first = true;
                }
            }
        },*/

    loadEditRecordPage: function (row) {
        var _this = this;
        var model = Gikam.create('modal', {
            title: 'T_LIMS_EDIT_RECORD.SERVICE_NAME',
            height: '500',
            width: '680',
        });
        Gikam.create('layout', {
            renderTo: model.window.$dom,
            north: {
                height: '15%',
                items: [{
                    type: 'form',
                    id: 'search-form',
                    onRendered: function () {
                        Gikam.post(limsQualitycontrolTestBatch.editRecordUrl + '/queries', Gikam.getJsonWrapper({
                            f: {
                                orderTaskId_EQ: row.id,
                                testResult: 'testResult'
                            },
                            o: [{'editedTime': 'asc'}]
                        })).done(function (data) {
                            Gikam.getComp('view-edit-record-grid').loadData(data.rows);
                        })
                    },
                    fields: [{
                        field: 'fieldName',
                        title: 'T_LIMS_EDIT_RECORD.FIELDNAME.SELECT.TITLE',
                        type: 'select',
                        category: 'sys',
                        value: 'testResult',
                        param: {
                            codeCategoryId: 'fieldName-select'
                        },
                        firstBlank: false,
                        onChange: function (field, value, rowIndex, oldValue, text) {
                            if (value === 'testResult') {
                                Gikam.post(limsQualitycontrolTestBatch.editRecordUrl + '/queries', Gikam.getJsonWrapper({
                                    f: {
                                        orderTaskId_EQ: row.id,
                                        testResult: value
                                    },
                                    o: [{'editedTime': 'asc'}]
                                })).done(function (data) {
                                    Gikam.getComp('view-edit-record-grid').loadData(data.rows);
                                })
                            } else {
                                Gikam.post(limsQualitycontrolTestBatch.editRecordUrl + '/queries', Gikam.getJsonWrapper({
                                    f: {
                                        orderTaskId_EQ: row.id,
                                        fieldName_EQ: value
                                    },
                                    o: [{'editedTime': 'asc'}]
                                })).done(function (data) {
                                    Gikam.getComp('view-edit-record-grid').loadData(data.rows);
                                })
                            }
                        }
                    }], columns: 2, titleWidth: 130
                }]
            },
            center: {
                items: [{
                    type: 'grid',
                    id: 'view-edit-record-grid',
                    columns: limsQualitycontrolTestBatch.getOrderTaskEditRecordColumns(),
                    // url: Gikam.printf(limsQualitycontrolTestBatch.editRecordUrl + '/{orderTaskId}', {
                    //     orderTaskId: row.id
                    // }),
                    generalButtonGroup: false,
                    order: {'editedTime': 'asc'},
                    toolbar: []
                },]
            }
        })
    },

    create: function () {
        var _this = this;
        Gikam.create('layout', {
            id: 'lims-qualitycontrol-test-batch-edit-list-layout',
            renderTo: workspace.window.$dom,
            // north: {
            //     items: [this.getMainTab()],
            //     height: '50%'
            // },
            center: {
                items: [this.getMainResultTabs()],
            }
        });
    }
    ,

    init: function () {
        this.create();
    }
};
